#include"udpsocket.hpp"

#define CHECK_RET(r) if((r) == false){return -1;}

int main(int argc,char* argv[])
{
    if(argc!=3){
        std::cout<<"usage:./udp_cli 127.0.0.1 9000\n";
        return -1;
    }
    UdpSocket us;
    //1.创建套接字
    CHECK_RET(us.Socket());
    //2.绑定地址信息（不推荐）
    while(1){
        std::string buf;
        std::cout<<"client say:";
        fflush(stdout);
        std::cin>>buf;
        //3.发送数据
        CHECK_RET(us.Send(buf,argv[1],std::stoi(argv[2])));
        //4.接受数据
        buf.clear();
        CHECK_RET(us.Recv(&buf));
        std::cout<<"server say:"<<buf<<std::endl;
    }
    //5.关闭套接字
    us.Close();
    return 0;
}